import 'package:audio_session/audio_session.dart' as audio_session;
import '../../enums/enums.dart';

/// Information about an audio device. If you require platform specific device
/// details, use [AVAudioSession] and [AndroidAudioManager] directly.
class AudioDevice {
  /// The unique ID of the device.
  final String id;

  /// The name of the device.
  final String name;

  /// Whether this device is an input.
  final bool isInput;

  /// Whether this device is an output.
  final bool isOutput;

  /// The type of this device.
  final AudioDeviceType type;

  AudioDevice({
    required this.id,
    required this.name,
    required this.isInput,
    required this.isOutput,
    required this.type,
  });

  AudioDevice.from(audio_session.AudioDevice audioDevice):
      id = audioDevice.id,
      name = audioDevice.name,
      isInput = audioDevice.isInput,
      isOutput = audioDevice.isOutput,
      type = AudioDeviceType.values[audioDevice.type.index];

  @override
  int get hashCode => id.hashCode;

  @override
  bool operator ==(Object other) => other is AudioDevice && id == other.id;

  @override
  String toString() =>
      'AudioDevice(id:$id,name:$name,isInput:$isInput,isOutput:$isOutput,type:$type)';
}